﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Xml;
using System.Text;

public partial class RSSFeed : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Clear();
		Response.ContentType = "text/xml";
        
		XmlTextWriter objX = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
		objX.WriteStartDocument();
		objX.WriteStartElement("rss");
		objX.WriteAttributeString("version","2.0");
		objX.WriteStartElement("channel");
		objX.WriteElementString("title", "P.A.N.D.A. RSS Feed");
		objX.WriteElementString("link","http://www.lordorix.tumblr.com");
		objX.WriteElementString("description","The latest updates for major disasters and incidents in Australia");
		objX.WriteElementString("copyright","(c) 2010 Patrick Gordon wrote this whold damn site.");
		objX.WriteElementString("ttl","15");

        string connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|Database.accdb;Persist Security Info=True";
        string selectState = "SELECT * FROM Incidents";

        OleDbConnection objConnec = new OleDbConnection(connString);
        objConnec.Open();

        OleDbCommand objCommand = new OleDbCommand(selectState, objConnec);
        OleDbDataReader objReader = objCommand.ExecuteReader();

        while (objReader.Read())
		{
			objX.WriteStartElement("item");
			objX.WriteElementString("description", objReader.GetString(2));
            objX.WriteElementString("title", objReader.GetString(3));
            objX.WriteElementString("pubDate", objReader.GetDateTime(8).ToString("R"));
			objX.WriteEndElement();
		}
        
		objReader.Close();
		objConnec.Close();

		objX.WriteEndElement();
		objX.WriteEndElement();
		objX.WriteEndDocument();
		objX.Flush();
		objX.Close();
		Response.End();

    }

}